<template>
  <view v-if="template">
    <!--  :bgStyle="template.style?.background" -->
    <!-- :navbarStyle="template.style?.navbar" -->
    <!-- #ifdef APP-PLUS -->
    <view class="h-[2.75rem]"></view>
    <!-- #endif -->
    <s-layout
      title="首页"
      navbar=""
      tabbar="/pages/index/index"
      onShareAppMessage
      class="page_main"
      :bgStyle="template.style?.background"
      :navbarStyle="template.style?.navbar"
    >
      <s-block v-for="(item, index) in template.data" :key="index" :styles="item.style">
        <s-block-item :type="item.type" :data="item.data" :styles="item.style" />
      </s-block>
      <s-popup-image />
    </s-layout>
  </view>
</template>

<script setup>
  import { computed } from 'vue';
  import { onLoad, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
  import sheep from '@/sheep';
  import $share from '@/sheep/platform/share';

  // 隐藏原生tabBar
  uni.hideTabBar({
    fail: () => {},
  });

  const template = computed(() => sheep.$store('app').template?.home);

  onLoad((options) => {
    console.log('🚀 ~ options:', options);
    // #ifdef MP
    // 小程序识别二维码
    if (options.scene) {
      const sceneParams = decodeURIComponent(options.scene).split('=');
      options[sceneParams[0]] = sceneParams[1];
    }
    // #endif

    // 预览模板
    if (options.templateId) {
      sheep.$store('app').init(options.templateId);
    }

    // 解析分享信息
    if (options.spm) {
      $share.decryptSpm(options.spm);
    }

    // 进入指定页面(完整页面路径)
    if (options.page) {
      sheep.$router.go(decodeURIComponent(options.page));
    }
  });

  // 下拉刷新
  onPullDownRefresh(() => {
    sheep.$store('app').init();
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 800);
  });

  onPageScroll(() => {});
</script>

<style lang="scss" scoped>
  // :deep(.page_main) {
  //   background: linear-gradient(180deg, #0984c0 0%, #f1f6f7 100%) !important;
  // }
  // :deep(.page-main) {
  //   background: linear-gradient(180deg, #0984c0 0%, #f1f6f7 100%) !important;
  // }
  :deep(.page-body) {
    background: linear-gradient(180deg, #0984c0 0%, #f1f6f7 400px) !important;
  }
  // :deep(page) {
  //   background: linear-gradient(180deg, #0984c0 0%, #f1f6f7 100%) !important;
  // }
  // :deep(.page-app) {
  //   background: linear-gradient(180deg, #0984c0 0%, #f1f6f7 100%) !important;
  // }
</style>
